var form;
$(function() {
	getTables();
	form = layui.form;
	/* 监听提交 */
	form.on('submit(submit-btn)', function(data) {
		makeFile();
		return false;
	});
	form.on('select(dataSource)', function(data){
		getTables();
	});
	form.on('select(tableName)', function(data){
		getFields()();
	});
	form.render();
	
});
function getTables() {
	$.ajax({
			url : webPath + "/codeSign/code/getTables",
			data : "dataSource=" + $("#dataSource").val(),
			success : function(retData) {
				$("#tableName").empty();
				for (var i = 0; i < retData.length; i++) {
					var tableName = retData[i];
					$("#tableName").append(
							"<option value='" + tableName.TABLE_NAME + "'>" + tableName.TABLE_NAME
									+ "</option>");
				}
				getFields();
				form.render();
			},
			dataType : "json"
	});
}

function getFields() {
	$.ajax({
			url : webPath + "/codeSign/code/getColunms",
			data : "dataSource=" + $("#dataSource").val() + "&tableName=" + $("#tableName").val(),
			success : function(retData) {
				$("#allFields").empty();
				for (var i = 0; i < retData.length; i++) {
					var field = retData[i];
					var fieldName = field.ID
					if (undefined != field.NAME && "" != field.NAME) {
						fieldName = field.NAME;
					}
					$("#allFields").append(
							"<input type=\"checkbox\" name=\"searchFields\"  lay-skin=\"primary\" value='"
									+ field.ID + "_________ROUBSITE________" + fieldName
									+ "' id=\"" + field.ID + "\" title='" + fieldName
									+ "'><br /> ");
				}
				form.render();
			},
			dataType : "json"
	});
}